package com.jt.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
public class MyMetaObjectHandler implements MetaObjectHandler {

    //入库时
    @Override
    public void insertFill(MetaObject metaObject) { //上方传过来的信息
        Date date = new Date();
        //根据属性名设置值，记得将上边传来的参数代入
        this.setFieldValByName("created", date,metaObject);
        this.setFieldValByName("updated", date,metaObject);
    }
    //更新时
    @Override
    public void updateFill(MetaObject metaObject) {
        this.setFieldValByName("updated",new Date(),metaObject);
    }
}
